<%-- 
    Document   : NewOrder
    Created on : Jul 30, 2012, 2:25:17 PM
    Author     : RasJLK
--%>

<%@page import="java.text.DateFormat"%>
<%@page import="ejb.CustomerOrder"%>
<%@page import="java.util.Iterator"%>
<%@page import="ejb.Customer"%>
<%@page import="java.util.List"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Add/Edit Order</title>
        <link rel="stylesheet" type="text/css" href="style.css" media="screen" />
    </head>
    <body>
        <%
            List<Customer> customers = (List<Customer>) request.getAttribute("customers");
            CustomerOrder order = (CustomerOrder) request.getAttribute("order");
            Customer orderCust = null;
            if (order != null) {
                orderCust = order.getCustomer();
            }
            Iterator custIt = null;
            if (customers != null) {
                custIt = customers.iterator();
            }
        %>
        <form method="POST" action="SaveOrder">
            <table>
            <caption>Order Details</caption>
                <tr>
                    <td>Order No:</td>
                    <td><input type="text" name="orderNo" value="<%= order != null ? order.getOrderNo() : ""%>" /></td>
                </tr>
                <tr>
                    <td>Customer:</td>
                    <td>
                        <select name="customerId" editable="true">
                            <%
                                if (custIt != null) {
                                    while (custIt.hasNext()) {
                                        Customer c = (Customer) custIt.next();
                                        if (orderCust != null && c.getId() == orderCust.getId()) {
                                            out.println("<option value=\"" + c.getId() + "\" selected=\"true\" >" + c.getName() + "</option>");
                                        } else {
                                            out.println("<option value=\"" + c.getId() + "\">" + c.getName() + "</option>");
                                        }
                                    }
                                }
                            %>

                        </select>
                    </td>
                </tr>
                <tr>
                    <td>Amount:</td>
                    <td><input type="text" name="ammount" value="<%= order != null ? order.getAmmount() : ""%>" /></td>
                </tr>
                <tr>
                    <td>Due Date:</td>
                    <td>
                        <input type="text" name="dueDate" value="<%= order != null ? DateFormat.getDateInstance(DateFormat.SHORT).format(order.getDueDate()) : ""%>" />
                        <br/> <strong> Note - Date format MM/DD/YY </strong>
                    </td>
                </tr>
                <tr>
                    <td>Comments:</td>
                    <td><textarea name="comments" class="big"><%= order != null ? order.getComments() : ""%></textarea></td>
                </tr>
                <tr>
                    
                    <td colspan="2"><input type="submit" value="Add/Edit Order" /> <a href="CustomerList">View Customers</a> </td>
                </tr>
            </table>
                <input type="hidden" value="<%= order != null ? order.getId() : "null" %>" name="id" />
        </form>
    </body>
</html>
